<?php
$APPID = "wx763167db8165c6d0";
$APPSECRET = "360b6c1227041ad97fa30ea0fc51fb23";

class WeiInfo {
	
	public function getOpenId(){

		$code = isset($_GET['code']) ? htmlspecialchars($_GET['code']) : '';
		//获取OPENID
		$get_taken_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx763167db8165c6d0&secret=360b6c1227041ad97fa30ea0fc51fb23&code=" .$code."&grant_type=authorization_code";
		//var_dump($get_taken_url);


		// 创建一个cURL资源
		$ch = curl_init();

		// 设置URL和相应的选项
		curl_setopt($ch, CURLOPT_URL, $get_taken_url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
		// 抓取URL并把它传递给浏览器
		$res =  curl_exec($ch);

		// 关闭cURL资源，并且释放系统资源
		curl_close($ch);

		$user_obj = json_decode($res,true);

		//print_r($res);

		//var_dump($user_obj); 

		if(!empty($user_obj["errcode"])){
			
			$open_id = "getfalse";
			return $open_id;
		
		}else{
			
			
			$open_id = $user_obj["openid"];	
			//setcookie("openid",$open_id,time()+7200);
			//var_dump($open_id);
			return $open_id;

		}
	
	}

}
?>